import os, re, sys

pattern = re.compile(sys.argv[1])

# read files and search pattern in files 
for root, dirs, files in os.walk(""):
    for f in files:
        if f.endswith(".py"):
            path = os.path.join(root, f)
            lineNum = 1
            for line in file(path):
                for m in pattern.finditer(line):
                    print "%s %d: %s" % (path, 
                        lineNum, m.group())
                lineNum += 1